﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Startup.Shell.Domain;
using Startup.Shell.ModelDesignerPreview;

namespace Startup.Shell.Modules.WindowDesignerModule
{
	/// <summary>
	/// Interaction logic for WindowDesignerView.xaml
	/// </summary>
	public partial class WindowDesignerView
	{
		private Point _startPoint;

		public WindowDesignerView()
		{
			InitializeComponent();
		}

		private void OnImageMouseMove(object sender, MouseEventArgs e)
		{
			// Get the current mouse position
			Point mousePos = e.GetPosition(null);
			Vector diff = _startPoint - mousePos;

			if (e.LeftButton == MouseButtonState.Pressed &&
				Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
				Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
			{
				if (sender is Image)
				{
					var image = (Image) sender;
					var preview = (IDesignerPreview) image.DataContext;

					// Initialize the drag & drop operation
					DataObject dragData = new DataObject("IDesignerPreview", preview);
					DragDrop.DoDragDrop(image, dragData, DragDropEffects.Move);
				}
				else if (sender is Border)
				{
					var border = (Border)sender;
					var property = (StartupProperty)border.DataContext;

					// Initialize the drag & drop operation
					DataObject dragData = new DataObject("StartupProperty", property);
					DragDrop.DoDragDrop(border, dragData, DragDropEffects.Move);
				}
			}
		}

		private void OnImageMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			_startPoint = e.GetPosition(null);
		}
	}
}
